﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vds2465Telegrams
{
	public abstract class Telegram_Returning_VariableLength : Telegram_Returning
	{
		#region private member variables

		private readonly UserDataColl _userDataColl;

		#endregion private member variables

		#region constructor

		public Telegram_Returning_VariableLength(eDirection direction, byte address, eTelegramFunction_Returning telegramFunction_Returning,
			bool accessDemandFlag, bool dataFlowControlStopFlag, UserDataColl userDataColl)
			: base(direction, address, telegramFunction_Returning, accessDemandFlag, dataFlowControlStopFlag)
		{
			_userDataColl = new UserDataColl();
			if (userDataColl != null)
			{
				foreach (UserData userData in userDataColl)
				{
					_userDataColl.Add(userData);
				}
			}
		}

		#endregion constructor

		#region public methods

		public UserDataColl GetCopyOfUserDataColl()
		{
			UserDataColl userDataColl = new UserDataColl();
			if (_userDataColl != null)
			{
				foreach (UserData userData in _userDataColl)
				{
					userDataColl.Add(userData);
				}
			}

			return userDataColl;
		}

		#endregion public methods

		#region ToString, Equals, GetHashCode

		public override int GetHashCode()
		{
			int hashCode = base.GetHashCode();
			hashCode ^= _userDataColl.Count;

			return hashCode;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("(");
			stringBuilder.Append(ToStringProperties());
			stringBuilder.Append(")");

			return stringBuilder.ToString();
		}

		internal override string ToStringProperties()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(base.ToStringProperties());
			stringBuilder.Append(", ");

			stringBuilder.Append("TheUserDataColl=");
			stringBuilder.Append(_userDataColl.ToString());
			return stringBuilder.ToString();
		}

		public override bool Equals(object obj)
		{
			Type objType = obj.GetType();
			if (this.GetType() == objType)
			{
				Telegram_Returning_VariableLength telegram2Compare = obj as Telegram_Returning_VariableLength;
				return EqualsProperties(telegram2Compare);
			}

			return false;
		}

		internal bool EqualsProperties(Telegram_Returning_VariableLength telegram2Compare)
		{
			if (base.EqualsProperties(telegram2Compare))
			{
				return (_userDataColl.Equals(telegram2Compare._userDataColl));
			}

			return false;
		}

		#endregion ToString, Equals, GetHashCode
	}
}
